<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>MyPetStore</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="../../css/bootstrap.min.css" rel="stylesheet" />
    <link href="../../font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="../../css/styleManage.css" rel="stylesheet" />

    <link href="../../css/plugins/iCheck/custom.css" rel="stylesheet"/>
    <link href="../../css/plugins/footable/footable.core.css" rel="stylesheet"/>
</head>
<body>
<script type="text/javascript">
    function fileupload() {
        var port = location.port;//获取当前端口号
        var categoryId = document.getElementById("categoryId").innerText;
        var name = document.getElementById("categoryName").value;
        console.log(categoryId+" "+name);
        var formdata = new FormData();
        //formdata.set(categoryId,name,$("#categoryDesc")[0].files[0]);
        formdata.append("file",$("#categoryDesc")[0].files[0]);
        formdata.append("categoryId",categoryId);
        formdata.append("name",name);
        $.ajax({
            type    :   "POST",
            url     :   "http://localhost:"+port+"/file/categoryImgEdit",//必须用绝对路径
            //data    :   {file:formdata,categoryId:categoryId,name:name},
            data    :   formdata,
            async:false,
            cache:false,
            processData: false,
            contentType :   false,
            success :   function (category) {
                alert("修改成功");
                $("#categoryImg").html("");
                $("#categoryImg").append(
                    "<label>图片:</label>\n" +
                    "<img src="+ category.description+"/>"+
                    "<input type=\"file\" id=\"categoryDesc\" class=\"file-control\"/>\n" +
                    "<input type=\"button\" class=\"navbar-minimalize minimalize-styl-2 btn btn-primary \" value=\"修改\" onclick=\"fileupload()\"/>"
                );
            }
        });
    }

</script>
<div id="wrapper">
    <nav class="navbar-default navbar-static-side" role="navigation" th:include="/manage/nav :: navigation"></nav>
    <div id="page-wrapper" class="gray-bg">
        <div class="border-bottom" th:include="/manage/header :: headerTop"></div>
        <div class="row wrapper border-bottom white-bg page-heading" th:fragment="headerNav">
            <div class="col-lg-10">
                <h2>商品管理</h2>
                <ol class="breadcrumb">
                    <li>
                        <a th:href="@{/manage/viewCategory}">首页</a>
                    </li>
                    <li class="active">
                        <a href="/manage/viewCategory">大类管理</a>
                    </li>
                    <li class="active">
                        <strong>修改大类</strong>
                    </li>
                </ol>
            </div>
            <div class="col-lg-2">
            </div>
        </div>

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>商品列表</h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <div class="table-responsive">
                                <h3 th:id="categoryId" th:text="${category.categoryId}"></h3>
                            </div>
                            <div class="table-responsive">
                                <label>类名:</label>
                                <input th:id="categoryName" class="form-control" name="top-search" id="top-search" placeholder="类名"/>
                            </div>
                            <div id="categoryImg" class="table-responsive">
                                <label>图片:</label>
                                <img th:src="${category.description}" th:height="150" th:width="150"/>
                                <input type="file" id="categoryDesc" class="file-control"/>
                                <input type="button" class="navbar-minimalize minimalize-styl-2 btn btn-primary " th:value="修改" th:onclick="fileupload()"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer" th:include="/manage/footer :: copyright"></div>
    </div>
</div>

<!-- Mainly scripts -->
<script th:src="@{../../js/jquery-2.1.1.js}"></script>
<script th:src="@{../../js/bootstrap.min.js}"></script>
<script th:src="@{../../js/plugins/metisMenu/jquery.metisMenu.js}"></script>
<script th:src="@{../../js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>

<!-- Peity -->
<script th:src="@{../../js/plugins/peity/jquery.peity.min.js}"></script>

<!-- Custom and plugin javascript -->
<script th:src="@{../../js/inspinia.js}"></script>
<script th:src="@{../../js/plugins/pace/pace.min.js}"></script>

<!-- iCheck -->
<script th:src="@{../../js/plugins/iCheck/icheck.min.js}"></script>

<!-- Peity -->
<script th:src="@{../../js/demo/peity-demo.js}"></script>

<!-- FooTable -->
<script th:src="@{../../js/plugins/footable/footable.all.min.js}"></script>

<!-- common -->
<script th:src="@{../../js/common.js}"></script>

<script th:inline="javascript">
    var pageHTML = [[${pageHTML}]];
    $(document).ready(function () {
        $("#pageHTML").html(pageHTML);
    });

    /*<![CDATA[*/
    function updateState(id,state,commendState){
        var deleteTag;
        if(state==2){
            deleteTag = confirm("确定删除此条信息?");
        } else {
            deleteTag = true;
        }
        if(deleteTag){
            $.ajax({
                type: "POST",
                url: "itemEditState?id="+id,
                contentType: "application/json; charset=utf-8",
                success: function(msg){
                    window.location.reload();
                },
                error: function(){
                    alert("系统异常！");
                }
            });
        }
    }
    /*]]>*/
</script>



</body>
</html>